package com.shigen.file.controller;

import com.shigen.file.annotation.RequestLimit;
import com.shigen.file.common.Result;
import com.shigen.file.req.UserRequest;
import com.shigen.file.service.IUserService;
import com.shigen.file.util.IPUtil;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author shigen.fu
 * @since 2022-06-04
 */
@RestController
@RequestMapping("/file/user")
public class UserController {
  @Resource
  private IUserService userService;

  /**
   * 用户登录
   */
  @PostMapping(value = "login")
  @RequestLimit(count = 3)
  @ApiOperation(value = "用户登录")
  public Result login(@RequestBody @Valid UserRequest.Login login, HttpServletRequest request) {
    String ip = IPUtil.getIp(request);
    String userAgent = request.getHeader("User-Agent");
    return userService.login(login, ip, userAgent);
  }
}
